/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.client.ZGetInfoResult;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.common.auth.ZAuthToken;
/*     */ import com.zimbra.common.httpclient.HttpClientUtil;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.common.soap.W3cDomUtil;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.soap.JaxbUtil;
/*     */ import com.zimbra.soap.mail.message.CreateWaitSetRequest;
/*     */ import com.zimbra.soap.mail.message.CreateWaitSetResponse;
/*     */ import com.zimbra.soap.mail.message.WaitSetRequest;
/*     */ import com.zimbra.soap.mail.message.WaitSetResponse;
/*     */ import com.zimbra.soap.type.WaitSetAddSpec;
/*     */ import java.io.IOException;
/*     */ import javax.xml.bind.Marshaller;
/*     */ import junit.framework.TestCase;
/*     */ import org.apache.commons.httpclient.HttpClient;
/*     */ import org.apache.commons.httpclient.HttpException;
/*     */ import org.apache.commons.httpclient.methods.PostMethod;
/*     */ import org.apache.commons.httpclient.methods.StringRequestEntity;
/*     */ import org.dom4j.Document;
/*     */ import org.dom4j.io.DocumentResult;
/*     */ import org.junit.Assert;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestWaitSetRequest
/*     */   extends TestCase
/*     */ {
/*     */   private static final String USER_NAME = "user1";
/*  52 */   private static final String NAME_PREFIX = TestWaitSetRequest.class.getSimpleName();
/*     */   private Marshaller marshaller;
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  58 */     cleanUp();
/*  59 */     this.marshaller = JaxbUtil.createMarshaller();
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/*  64 */     cleanUp();
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception {
/*  68 */     TestUtil.deleteTestData("user1", NAME_PREFIX);
/*     */   }
/*     */   
/*     */   private String envelope(String authToken, String requestBody) {
/*  72 */     return "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"><soap:Header><context xmlns=\"urn:zimbra\"><userAgent name=\"Zimbra Junit\" version=\"0.0\"/><authToken>" + authToken + "</authToken>" + "<nosession/>" + "</context>" + "</soap:Header>" + "<soap:Body>" + requestBody + "</soap:Body>" + "</soap:Envelope>";
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private Object sendReq(String requestBody, String requestCommand)
/*     */     throws HttpException, IOException, ServiceException
/*     */   {
/*  87 */     HttpClient client = new HttpClient();
/*  88 */     PostMethod post = new PostMethod(TestUtil.getSoapUrl() + requestCommand);
/*  89 */     post.setRequestEntity(new StringRequestEntity(requestBody, "application/soap+xml", "UTF-8"));
/*  90 */     int respCode = HttpClientUtil.executeMethod(client, post);
/*  91 */     Assert.assertEquals(200L, respCode);
/*  92 */     com.zimbra.common.soap.Element envelope = W3cDomUtil.parseXML(post.getResponseBodyAsStream());
/*  93 */     SoapProtocol proto = SoapProtocol.determineProtocol(envelope);
/*  94 */     com.zimbra.common.soap.Element doc = proto.getBodyElement(envelope);
/*  95 */     return JaxbUtil.elementToJaxb(doc);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testWaitSetRequest() throws Exception {
/* 100 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/*     */     
/* 102 */     String authToken = mbox.getAuthToken().getValue();
/* 103 */     CreateWaitSetRequest req = new CreateWaitSetRequest("all");
/* 104 */     WaitSetAddSpec add = new WaitSetAddSpec();
/* 105 */     add.setId(mbox.getAccountInfo(false).getId());
/* 106 */     req.addAccount(add);
/* 107 */     DocumentResult dr = new DocumentResult();
/* 108 */     this.marshaller.marshal(req, dr);
/* 109 */     Document doc = dr.getDocument();
/* 110 */     ZimbraLog.test.info(doc.getRootElement().asXML());
/* 111 */     CreateWaitSetResponse createResp = (CreateWaitSetResponse)sendReq(envelope(authToken, doc.getRootElement().asXML()), "CreateWaitSetRequest");
/*     */     
/* 113 */     String waitSetId = createResp.getWaitSetId();
/* 114 */     Assert.assertNotNull(waitSetId);
/*     */     
/* 116 */     WaitSetRequest waitSet = new WaitSetRequest(waitSetId, "0");
/* 117 */     dr = new DocumentResult();
/* 118 */     this.marshaller.marshal(waitSet, dr);
/* 119 */     doc = dr.getDocument();
/*     */     
/* 121 */     WaitSetResponse wsResp = (WaitSetResponse)sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
/* 122 */     Assert.assertEquals("0", wsResp.getSeqNo());
/* 123 */     String subject = NAME_PREFIX + " test wait set request 1";
/* 124 */     TestUtil.addMessageLmtp(subject, "user1", "user999@example.com");
/* 125 */     try { Thread.sleep(500L); } catch (Exception e) {}
/* 126 */     wsResp = (WaitSetResponse)sendReq(envelope(authToken, doc.getRootElement().asXML()), "WaitSetRequest");
/* 127 */     Assert.assertFalse(wsResp.getSeqNo().equals("0"));
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestWaitSetRequest.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */